<template>
    <div class="app-container">
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        label-width="100px"
      >
      <el-form-item label="类型" prop="configType">
        <el-select
          v-model="queryParams.configType"
          style="width: 215px"
          placeholder="请选择类型"
          filterable
          clearable
          size="small"
        >
          <el-option
            v-for="dict in tableTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="配置名称" prop="uniqueKeyName">
        <el-input
          v-model="queryParams.uniqueKeyName"
          placeholder="请输入配置名称"
          clearable
          size="small"
          style="width: 215px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
        <!-- <el-form-item label="平台" prop="platform">
          <el-select
            v-model="queryParams.platform"
            style="width: 215px"
            placeholder="请选择平台"
            filterable
            clearable
            size="small"
          >
            <el-option
              v-for="dict in platformList"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item
          label="店铺名称"
          prop="shopId"
        >
          <el-select
            v-model="queryParams.shopId"
            placeholder="请选择店铺名称"
            clearable
            size="small"
            style="width: 215px"
            filterable
            @focus="getListShop()"
            :remote-method="getListShop"
          >
            <el-option
              v-for="item in shopList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item> -->
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            v-hasPermi="['sysDynamicTableConfig:sysDynamicTableConfig:add']"
            @click="handleAdd"
            >新增</el-button
          >
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @handleQuery="handleQuery"
          @resetQuery="resetQuery"
        ></right-toolbar>
      </el-row>
  
      <el-table
        v-loading="loading"
        :data="companyList"
        v-adaptive="{ bottomOffset: 50 }"
        height="100px"
      >
        <el-table-column
          label="配置模块"
          min-width="150"
          align="center"
          prop="configType"
        >
          <template slot-scope="scope">
            <span>{{ statue(scope.row.configType, tableTypeOptions) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="配置名称"
          min-width="150"
          align="center"
          prop="uniqueKeyName"
        />
        <el-table-column
          label="操作"
          width="150"
          align="center"
          fixed="right"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleDetail(scope.row)"
              v-hasPermi="['sysDynamicTableConfig:sysDynamicTableConfig:query']"
              style="margin-right: 5px"
              >详情</el-button
            >
            <el-button
              size="mini"
              type="text"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['sysDynamicTableConfig:sysDynamicTableConfig:edit']"
              style="margin-right: 5px"
              >修改</el-button
            >
            <el-button
              size="mini"
              type="text"
              @click="handleDeletel(scope.row)"
              v-hasPermi="['sysDynamicTableConfig:sysDynamicTableConfig:remove']"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <div v-if="activate"></div>
    </div>
  </template>
  
  <script>
  import {
    sysDynamicTableConfigList,
    sysDynamicTableConfigDelete
  } from "@/api/common/importProfile";
  import { listShop } from "@/api/member/shop";
  export default {
    name: "Label",
    components: {},
    data() {
      return {
        open: false,
        title: "",
        activate: true,
        // 遮罩层
        loading: false,
        form: {},
        // 显示搜索条件
        showSearch: false,
        // 总条数
        total: 0,
        // 表格数据
        companyList: [],
        //菜单名称
        platformList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
        },
        //类型
        tableTypeOptions:[],
        //店铺
        shopList:[]
      };
    },
    created() {
      // 类型
      this.getDicts("sys_dynamic_table_type").then((response) => {
      this.tableTypeOptions = response.data;
    });
    this.getDicts("sys_platform_type").then((res) => {
        this.platformList = res.data;
      });
      this.getList();
    },
    //触发回流
    activated() {
      this.activate = false;
      setTimeout(() => {
        this.activate = true;
      });
      this.getList();
    },
    methods: {
        //获取店铺
    async getListShop(name) {
      let response = await listShop({ name: name });
      this.shopList = response.data;
    },
      /** 查询商品信息列表 */
      getList() {
        this.loading = true;
        sysDynamicTableConfigList(this.queryParams).then((response) => {
          this.companyList = response.data;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
        };
        this.handleQuery();
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.$router.push("/common/addImport");
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.$router.push("/common/addImportEdit/" + row.id);
      },
      handleDetail(row){
        this.$router.push("/common/addImportDetails/" + row.id);
      },
      handleDeletel(row) {
        this.$confirm(
          "是否确认删除配置名称为 “" + row.uniqueKeyName + "” 的数据项？",
          "警告",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        ).then(() => {
          sysDynamicTableConfigDelete(row.id).then((res) => {
            this.getList();
            this.msgSuccess("操作成功");
          });
        });
      },
    },
  };
  </script>
  <style lang="scss" scoped>
  .treeselect-main {
    width: 193px;
  }
  </style>
  